package com.jsu.config;

import com.rabbitmq.client.ConnectionFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * 生产者
 */
@Component
public class MessageProducer {

    @Resource
    private RabbitTemplate rabbitTemplate;

    public void sendDelayQueue(Integer id, Integer delayTime) {

        // 三个参数
        rabbitTemplate.convertAndSend(RabbitMqConfig.DELAY_EXCHANGE_NAME,
                RabbitMqConfig.DELAY_QUEUE_ROUTING_KEY,id,
                message1 -> {
                    //设置延时时间
                    message1.getMessageProperties().setDelay(delayTime);
                    return message1;
                });
    }

}
